package mdt.action;

import org.tigris.gef.base.Globals;

import javax.swing.*;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledEditorKit;
import java.awt.*;
import java.awt.event.ActionEvent;

/**
 * Created by xiaobyu on 7/14/2016.
 */
public class SetFillColorAction extends StyledEditorKit.StyledTextAction {
    public SetFillColorAction() {
        super("Set Text Background Color");
        putValue(Action.SMALL_ICON, new ImageIcon(FontBoldAction.class.getResource("/resources/fill_color-16.png")));
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        JTextPane jtp = (JTextPane) Globals.curEditor().getActiveTextEditor();
        Color color = JColorChooser.showDialog(jtp,"Select a color", Color.white);
        MutableAttributeSet attr = new SimpleAttributeSet();
        StyleConstants.setBackground(attr, color);
        setCharacterAttributes(jtp, attr, false);
    }
}
